package com.lg.partition15;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/27 22:52
 */
public class P1434滑雪 {

    private static final int N = 110;
    private static final int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    private static int[][] g = new int[N][N], f = new int[N][N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) {
            ss = reader.readLine().split(" ");
            for (int j = 1; j <= m; j++) {
                g[i][j] = Integer.parseInt(ss[j - 1]);
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                ans = Math.max(ans, dfs(i, j));
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int dfs(int x, int y) {
        if (f[x][y] != 0) return f[x][y];
        f[x][y]++;
        for (int[] dir : dirs) {
            int nx = x + dir[0], ny = y + dir[1];
            if (nx < 1 || nx > n || ny < 1 || ny > m || g[nx][ny] >= g[x][y]) continue;
            f[x][y] = Math.max(f[x][y], dfs(nx, ny) + 1);
        }
        return f[x][y];
    }
}
